<div class="d-flex justify-content-center">
  <div class="col-8">
    <form name="editForm" novalidate (ngSubmit)="save()" [formGroup]="editForm">
      <h2 id="jhi-post-heading" data-cy="PostCreateUpdateHeading" jhiTranslate="blogApp.post.home.createOrEditLabel">
        Create or edit a Post
      </h2>

      <div>
        <jhi-alert-error></jhi-alert-error>

        @if (editForm.controls.id.value !== null) {
          <div class="mb-3">
            <label class="form-label" for="field_id" jhiTranslate="blogApp.post.id">ID</label>
            <input type="number" class="form-control" name="id" id="field_id" data-cy="id" formControlName="id" [readonly]="true" />
          </div>
        }

        <div class="mb-3">
          <label class="form-label" for="field_title" jhiTranslate="blogApp.post.title">Title</label>
          <input type="text" class="form-control" name="title" id="field_title" data-cy="title" formControlName="title" />
          @if (editForm.get('title')!.invalid && (editForm.get('title')!.dirty || editForm.get('title')!.touched)) {
            <div>
              @if (editForm.get('title')?.errors?.required) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.required">This field is required.</small>
              }
            </div>
          }
        </div>

        <div class="mb-3">
          <label class="form-label" for="field_content" jhiTranslate="blogApp.post.content">Content</label>
          <textarea class="form-control" name="content" id="field_content" data-cy="content" formControlName="content"></textarea>
          @if (editForm.get('content')!.invalid && (editForm.get('content')!.dirty || editForm.get('content')!.touched)) {
            <div>
              @if (editForm.get('content')?.errors?.required) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.required">This field is required.</small>
              }
            </div>
          }
        </div>

        <div class="mb-3">
          <label class="form-label" for="field_date" jhiTranslate="blogApp.post.date">Date</label>
          <div class="d-flex">
            <input
              id="field_date"
              data-cy="date"
              type="datetime-local"
              class="form-control"
              name="date"
              formControlName="date"
              placeholder="YYYY-MM-DD HH:mm"
            />
          </div>
          @if (editForm.get('date')!.invalid && (editForm.get('date')!.dirty || editForm.get('date')!.touched)) {
            <div>
              @if (editForm.get('date')?.errors?.required) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.required">This field is required.</small>
              }
              <small
                class="form-text text-danger"
                [hidden]="!editForm.get('date')?.errors?.datetimelocal"
                jhiTranslate="entity.validation.datetimelocal"
                >This field should be a date and time.</small
              >
            </div>
          }
        </div>

        <div class="mb-3">
          <label class="form-label" for="field_blog" jhiTranslate="blogApp.post.blog">Blog</label>
          <select class="form-control" id="field_blog" data-cy="blog" name="blog" formControlName="blog" [compareWith]="compareBlog">
            <option [ngValue]="null"></option>
            @for (blogOption of blogsSharedCollection; track $index) {
              <option [ngValue]="blogOption">{{ blogOption.name }}</option>
            }
          </select>
        </div>

        <div class="mb-3">
          <label for="field_tags" jhiTranslate="blogApp.post.tag">Tag</label>
          <select class="form-control" id="field_tags" data-cy="tag" multiple name="tags" formControlName="tags" [compareWith]="compareTag">
            @for (tagOption of tagsSharedCollection; track $index) {
              <option [ngValue]="tagOption">{{ tagOption.name }}</option>
            }
          </select>
        </div>
      </div>

      <div>
        <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" (click)="previousState()">
          <fa-icon icon="ban"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
        </button>

        <button
          type="submit"
          id="save-entity"
          data-cy="entityCreateSaveButton"
          [disabled]="editForm.invalid || isSaving"
          class="btn btn-primary"
        >
          <fa-icon icon="save"></fa-icon>&nbsp;<span jhiTranslate="entity.action.save">Save</span>
        </button>
      </div>
    </form>
  </div>
</div>
